package DeadLockDemo;

import javax.crypto.spec.SecretKeySpec;
import java.security.*;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Random;
import java.util.stream.IntStream;

public class QuantumCrypto {
    // 定义加密相关类
    public static class CryPto {
        public static class KEM {
            public static KEM getInstance(String algorithm) {
                return new KEM();
            }

            public Encapsulator newEncapsulator(PublicKey publicKey) {
                return new Encapsulator();
            }

            public Decapsulator newDecapsulator(PrivateKey privateKey, Encapsulated enc) {
                return new Decapsulator();
            }

            public static class Encapsulator {
                public Encapsulated encapsulate() {
                    return new Encapsulated();
                }
            }

            public static class Decapsulator {
                public byte[] decapsulate() {
                    return new byte[32];
                }
            }

            public static class Encapsulated {
                public Key key() {
                    return new SecretKeySpec(new byte[32], "AES");
                }
            }
        }
    }

    public static void main(String[] args) throws NoSuchAlgorithmException {
        // 1. 密钥对生成
        KeyPairGenerator kpg = KeyPairGenerator.getInstance("RSA"); // 改为实际支持的算法
        KeyPair kp = kpg.generateKeyPair();

        // 2. 密钥封装
        CryPto.KEM kem1 = CryPto.KEM.getInstance("KYBER");
        CryPto.KEM.Encapsulator sender = kem1.newEncapsulator(kp.getPublic());
        CryPto.KEM.Encapsulated enc = sender.encapsulate();
        byte[] secretKey = enc.key().getEncoded();

        // 3. 密钥解封
        CryPto.KEM kem2 = CryPto.KEM.getInstance("KYBER");
        CryPto.KEM.Decapsulator receiver = kem2.newDecapsulator(kp.getPrivate(), enc);
        byte[] secretKey2 = receiver.decapsulate();

        System.out.println("密钥匹配: " + Arrays.equals(secretKey, secretKey2));
        System.out.println("密钥1: " + Arrays.toString(secretKey));
        System.out.println("密钥2: " + Arrays.toString(secretKey2));

        // 示例列表操作
        ArrayList<String> list = new ArrayList<>();
        Collections.addAll(list, "1", "2", "3", "4", "5");
        System.out.println("列表内容: " + list);
        System.out.println("列表内容: " + list);

        IntStream ints = new Random().ints();
        IntStream ints2=new Random().ints();
        IntStream ints3=new Random().ints();
        System.out.println("ints: " + ints.sum());

        System.out.println("ints："+ints2.sum());
        System.out.println("int3"+ints3.sum());


      }
}
